package com.jl.jlapp.mvp.base;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Build.VERSION;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;

import com.jl.jlapp.R;

public abstract class BasePermActivity
        extends BaseActivity {
    private PermissionCall mPermissionCall;
    private final int permissionRequestCode = 110;

    private void requestPermission(final String[] paramArrayOfString, final int paramInt) {
        if (shouldShowRequestPermissionRationale(paramArrayOfString)) {
            new AlertDialog.Builder(this).setTitle(R.string.attention).setMessage(R.string.content_to_request_permission).setPositiveButton(R.string.ok, new OnClickListener() {
                public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt) {
                    ActivityCompat.requestPermissions(BasePermActivity.this, paramArrayOfString, paramInt);
                }
            }).show();
            return;
        }
        ActivityCompat.requestPermissions(this, paramArrayOfString, 110);
    }

    private boolean shouldShowRequestPermissionRationale(String[] paramArrayOfString) {
        boolean bool2 = false;
        int j = paramArrayOfString.length;
        int i = 0;
        for (; ; ) {
            boolean bool1 = bool2;
            if (i < j) {
                if (ActivityCompat.shouldShowRequestPermissionRationale(this, paramArrayOfString[i])) {
                    bool1 = true;
                }
            } else {
                return bool1;
            }
            i += 1;
        }
    }

    public boolean checkPermissionGranted(String... paramVarArgs) {
        boolean bool2 = true;
        int j = paramVarArgs.length;
        int i = 0;
        for (; ; ) {
            boolean bool1 = bool2;
            if (i < j) {
                if (ActivityCompat.checkSelfPermission(this, paramVarArgs[i]) != 0) {
                    bool1 = false;
                }
            } else {
                return bool1;
            }
            i += 1;
        }
    }

    public void onRequestPermissionsResult(int paramInt, @NonNull String[] paramArrayOfString, @NonNull int[] paramArrayOfInt) {
        if (paramInt == 110) {
            if (verifyPermissions(paramArrayOfInt)) {
                this.mPermissionCall.requestSuccess();
                this.mPermissionCall = null;
                return;
            }
            this.mPermissionCall.refused();
            this.mPermissionCall = null;
            return;
        }
        super.onRequestPermissionsResult(paramInt, paramArrayOfString, paramArrayOfInt);
    }

    public void requestRunTimePermissions(String[] paramArrayOfString, PermissionCall paramPermissionCall) {
        if ((paramArrayOfString == null) || (paramArrayOfString.length == 0)) {
            return;
        }
        this.mPermissionCall = paramPermissionCall;
        if ((Build.VERSION.SDK_INT < 23) || (checkPermissionGranted(paramArrayOfString))) {
            this.mPermissionCall.requestSuccess();
            return;
        }
        requestPermission(paramArrayOfString, 110);
    }

    public boolean verifyPermissions(int[] paramArrayOfInt) {
        if (paramArrayOfInt.length < 1) {
            return false;
        }
        for (int i = 0; i < paramArrayOfInt.length; i++) {
            if (paramArrayOfInt[i] != 0) {
                return false;
            }
        }
        return true;
    }

    public static abstract interface PermissionCall {
        public abstract void refused();

        public abstract void requestSuccess();
    }
}


/* Location:              /Users/davidzhang/Documents/decompileApk/jlfood-dex2jar.jar!/com/jl/jlapp/mvp/base/BasePermActivity.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */